package com.ssh;

import java.util.ArrayList;
import java.util.List;

public class PermuteUnique_47 {
	public static void main(String[] args) {
		int[] nums = {1,1,3};
		permuteUnique(nums);
		/*boolean[] u = new boolean[3];
		System.out.println(u[2]);*/
	}
	public static List<List<Integer>> permuteUnique(int[] nums) {
		List<List<Integer>> list = new ArrayList<List<Integer>>();
		boolean[] u = new boolean[nums.length];
		l(nums,list,new ArrayList<>(),u);
		return list;
	}
	private static void l (int[] nums, List<List<Integer>> list,List<Integer> l1,boolean u[]) {
		if (l1.size() == nums.length && !list.contains(l1)) {
			list.add(new ArrayList<>(l1));
			System.out.println("list="+list);
		}
		for (int i = 0; i < nums.length;i++) {
			if (u[i]) {
				continue;
			}
			l1.add(nums[i]);
			u[i] = true;
			System.out.println("l1="+l1);
			l(nums,list,l1,u);
			l1.remove(l1.size()-1);
			u[i] = false;
		}
	}
}